#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "scene.h"
#include "ctrlboard.h"
#include "mg_Lcd_Driver.h"
#include "mg_Device.h"
#include "mg_Rs485Protocol.h"
/* widgets:
Layer_Cdaos
Background_Cdaos
Container_Cdaos_On
Container_Cdaos_Button
PopupButton_Cdaos_OFF
Container_Cdaos_Mode_Fan
PopupButton_Cdaos_Fan
PopupButton_Cdaos_Mode7
PopupButton_Cdaos_Mode6
PopupButton_Cdaos_Mode5
PopupButton_Cdaos_Mode4
PopupButton_Cdaos_Mode3
PopupButton_Cdaos_Mode2
PopupButton_Cdaos_Mode1
Container_Cdaos_Only_Fan
PopupButton_Cdaos_Only_Fan
Container_Cdaos_Hum_On
Text_Cdaos_Hum_Item
Meter_Cdaos_Hum_Xuanzhuan
Icon_Cdaos_Hum_Pointer
CircleProgressBar_Cdaos_Hum
Icon_Cdaos_Hum_Jingdu
Container_Cdaos_CO2_On
Text_Cdaos_CO2_Item
Meter_Cdaos_CO2_Xuanzhuan
Icon_Cdaos_CO2_Pointer
CircleProgressBar_Cdaos_CO2
Icon_Cdaos_CO2_Jingdu
Container_Cdaos_PM25_On
Text_Cdaos_PM25_Item
Meter_Cdaos_PM25_Xuanzhuan
Icon_Cdaos_PM25_Pointer
CircleProgressBar_Cdaos_PM25
Icon_Cdaos_PM25_Jingdu
Container_Cdaos_Fan_On
Text_Cdaos_Fan_Item
Meter_Cdaos_Fan_Xuanzhuan
Icon_Cdaos_Fan_Pointer
CircleProgressBar_Cdaos_Fan
Icon_Cdaos_Fan_Jingdu
Text_Cdaos_Fan_Value
Container_Cdaos_Text
Container_Cdaos_Off
Icon_Cdaos_OFF
PopupButton_Cdaos_ON
Icon_Cdaos_Hum_Off
Icon_Cdaos_CO2_Off
Icon_Cdaos_PM25_Off
Icon_Cdaos_Fan_Off
Button_Back_MainMenu
*/
//支持的设置值
#define		CDOAS_SUPPOT_NULL	0		//不支持设置
#define 	CDOAS_SUPPOT_CO2	1		//支持设置CO2
#define 	CDOAS_SUPPOT_PM25	2		//支持设置PM2.5
#define 	CDOAS_SUPPOT_HUM	3		//支持设置湿度

//开关状态显示更新
void Cdoas_Switch_State_Update(uint8_t Switch_State);
//设置类型显示更新
void Cdoas_SetType_Update();
//风速状态显示更新
void Cdoas_Fan_State_Update(uint8_t Fan_State);
//模式状态显示更新
void Cdoas_Mode_State_Update(uint8_t Mode_State);
//设置值更新
void Cdoas_Set_Value_Update(uint16_t Set_Value);
//设置值更新
void Cdoas_Set_Value(uint16_t Set_Value);
//获取设置值
uint16_t Cdoas_Get_Set_Value(void);
static bool First_power_on = 0;//第一次上电标志位
static unsigned char cdos_dev_value = 0xFF;//第一次上电 由于收不到设备的参数 导致meter的值变成0  会发出去致使设备的实际值被变为 0

static ITUBackground* Background_Cdaos;
static ITUContainer* Container_Cdaos_Off;
static ITUIcon* Icon_Cdaos_Fan_Off;
static ITUIcon* Icon_Cdaos_PM25_Off;
static ITUIcon* Icon_Cdaos_CO2_Off;
static ITUIcon* Icon_Cdaos_Hum_Off;

static ITUContainer* Container_Cdaos_On;
static ITUContainer* Container_Cdaos_Fan_On;
static ITUContainer* Container_Cdaos_PM25_On;
static ITUContainer* Container_Cdaos_CO2_On;
static ITUContainer* Container_Cdaos_Hum_On;
static ITUContainer* Container_Cdaos_Only_Fan;
static ITUContainer* Container_Cdaos_Mode_Fan;
static ITUPopupButton* PopupButton_Cdaos_Mode[7];
static ITUMeter* Meter_Cdaos_Fan_Xuanzhuan;
static ITUMeter* Meter_Cdaos_PM25_Xuanzhuan;
static ITUMeter* Meter_Cdaos_CO2_Xuanzhuan;
static ITUMeter* Meter_Cdaos_Hum_Xuanzhuan;
static ITUCircleProgressBar	*CircleProgressBar_Cdaos_Fan;
static ITUCircleProgressBar	*CircleProgressBar_Cdaos_PM25;
static ITUCircleProgressBar	*CircleProgressBar_Cdaos_CO2;
static ITUCircleProgressBar	*CircleProgressBar_Cdaos_Hum;
static ITUText	*Text_Cdaos_Fan_Item;
static ITUText	*Text_Cdaos_PM25_Item;
static ITUText	*Text_Cdaos_CO2_Item;
static ITUText	*Text_Cdaos_Hum_Item;
static ITUText	*Text_Cdaos_Fan_Value;
static ITUText	*Text_Cdaos_PM25_Value;
static ITUText	*Text_Cdaos_CO2_Value;
static ITUText	*Text_Cdaos_Hum_Value;
static int MeterValue = 0, MeterValue_L = 0;
bool CdaosOnEnter(ITUWidget* widget, char* param)
{
	char WidgetTempName[30];
	uint8_t i;
	if (!Background_Cdaos)//首次加载
	{
		First_power_on = 1;
		Background_Cdaos = ituSceneFindWidget(&theScene, "Background_Cdaos");
		assert(Background_Cdaos);
		Container_Cdaos_Off = ituSceneFindWidget(&theScene, "Container_Cdaos_Off");
		assert(Container_Cdaos_Off);
		Icon_Cdaos_Fan_Off = ituSceneFindWidget(&theScene, "Icon_Cdaos_Fan_Off");
		assert(Icon_Cdaos_Fan_Off);
		Icon_Cdaos_PM25_Off = ituSceneFindWidget(&theScene, "Icon_Cdaos_PM25_Off");
		assert(Icon_Cdaos_PM25_Off);
		Icon_Cdaos_CO2_Off = ituSceneFindWidget(&theScene, "Icon_Cdaos_CO2_Off");
		assert(Icon_Cdaos_CO2_Off);
		Icon_Cdaos_Hum_Off = ituSceneFindWidget(&theScene, "Icon_Cdaos_Hum_Off");
		assert(Icon_Cdaos_Hum_Off);
		Container_Cdaos_On = ituSceneFindWidget(&theScene, "Container_Cdaos_On");
		assert(Container_Cdaos_On);
		Container_Cdaos_Fan_On = ituSceneFindWidget(&theScene, "Container_Cdaos_Fan_On");
		assert(Container_Cdaos_Fan_On);
		Container_Cdaos_PM25_On = ituSceneFindWidget(&theScene, "Container_Cdaos_PM25_On");
		assert(Container_Cdaos_PM25_On);
		Container_Cdaos_CO2_On = ituSceneFindWidget(&theScene, "Container_Cdaos_CO2_On");
		assert(Container_Cdaos_CO2_On);
		Container_Cdaos_Hum_On = ituSceneFindWidget(&theScene, "Container_Cdaos_Hum_On");
		assert(Container_Cdaos_Hum_On);
		Container_Cdaos_Only_Fan = ituSceneFindWidget(&theScene, "Container_Cdaos_Only_Fan");
		assert(Container_Cdaos_Only_Fan);
		Container_Cdaos_Mode_Fan = ituSceneFindWidget(&theScene, "Container_Cdaos_Mode_Fan");
		assert(Container_Cdaos_Mode_Fan);
		Meter_Cdaos_Fan_Xuanzhuan = ituSceneFindWidget(&theScene, "Meter_Cdaos_Fan_Xuanzhuan");
		assert(Meter_Cdaos_Fan_Xuanzhuan);
		Meter_Cdaos_PM25_Xuanzhuan = ituSceneFindWidget(&theScene, "Meter_Cdaos_PM25_Xuanzhuan");
		assert(Meter_Cdaos_PM25_Xuanzhuan);
		Meter_Cdaos_CO2_Xuanzhuan = ituSceneFindWidget(&theScene, "Meter_Cdaos_CO2_Xuanzhuan");
		assert(Meter_Cdaos_CO2_Xuanzhuan);
		Meter_Cdaos_Hum_Xuanzhuan = ituSceneFindWidget(&theScene, "Meter_Cdaos_Hum_Xuanzhuan");
		assert(Meter_Cdaos_Hum_Xuanzhuan);
		CircleProgressBar_Cdaos_Fan = ituSceneFindWidget(&theScene, "CircleProgressBar_Cdaos_Fan");
		assert(CircleProgressBar_Cdaos_Fan);
		CircleProgressBar_Cdaos_PM25 = ituSceneFindWidget(&theScene, "CircleProgressBar_Cdaos_PM25");
		assert(CircleProgressBar_Cdaos_PM25);
		CircleProgressBar_Cdaos_CO2 = ituSceneFindWidget(&theScene, "CircleProgressBar_Cdaos_CO2");
		assert(CircleProgressBar_Cdaos_CO2);
		CircleProgressBar_Cdaos_Hum = ituSceneFindWidget(&theScene, "CircleProgressBar_Cdaos_Hum");
		assert(CircleProgressBar_Cdaos_Hum);
		Text_Cdaos_Fan_Item = ituSceneFindWidget(&theScene, "Text_Cdaos_Fan_Item");
		assert(Text_Cdaos_Fan_Item);
		Text_Cdaos_PM25_Item = ituSceneFindWidget(&theScene, "Text_Cdaos_PM25_Item");
		assert(Text_Cdaos_PM25_Item);
		Text_Cdaos_CO2_Item = ituSceneFindWidget(&theScene, "Text_Cdaos_CO2_Item");
		assert(Text_Cdaos_CO2_Item);
		Text_Cdaos_Hum_Item = ituSceneFindWidget(&theScene, "Text_Cdaos_Hum_Item");
		assert(Text_Cdaos_Hum_Item);
		Text_Cdaos_Fan_Value = ituSceneFindWidget(&theScene, "Text_Cdaos_Fan_Value");
		assert(Text_Cdaos_Fan_Value);
		Text_Cdaos_PM25_Value = ituSceneFindWidget(&theScene, "Text_Cdaos_PM25_Value");
		assert(Text_Cdaos_PM25_Value);
		Text_Cdaos_CO2_Value = ituSceneFindWidget(&theScene, "Text_Cdaos_CO2_Value");
		assert(Text_Cdaos_CO2_Value);
		Text_Cdaos_Hum_Value = ituSceneFindWidget(&theScene, "Text_Cdaos_Hum_Value");
		assert(Text_Cdaos_Hum_Value);
		for (i = 0; i < 7; i++)
		{
			sprintf(WidgetTempName, "PopupButton_Cdaos_Mode%d", i);
			PopupButton_Cdaos_Mode[i] = ituSceneFindWidget(&theScene, WidgetTempName);
			assert(PopupButton_Cdaos_Mode[i]);
		}
		cdos_dev_value = Cdoas_Get_Set_Value();
	}
	else
	{
		First_power_on = 0;
	}
	//开关状态显示更新
	Cdoas_Switch_State_Update(TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Cdaos_Status.status);
	//设置类型显示更新
	Cdoas_SetType_Update();
	//风速状态显示更新
	Cdoas_Fan_State_Update(TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Cdaos_Status.Cdaos_Status_Value.Byte.FanSpeed);
	//模式状态显示更新
	Cdoas_Mode_State_Update(TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Cdaos_Status.Mode);
	//设置值状态显示更新
	Cdoas_Set_Value_Update(TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Cdaos_Status.Set_Value);

	//对标题进行语言转换
	if (Sys.Language == MG_LANGUAGE_CHS || Sys.Language == MG_LANGUAGE_ENG)
	{
		Text_Cdaos_Fan_Item->fontIndex = 0;
		Text_Cdaos_Fan_Item->boldSize = 1;
		ituTextSetFontSize(Text_Cdaos_Fan_Item, 18);
	}
	else if (Sys.Language == MG_LANGUAGE_ZHTW)
	{
		Text_Cdaos_Fan_Item->fontIndex = 8;
		Text_Cdaos_Fan_Item->boldSize = 0;
		ituTextSetFontSize(Text_Cdaos_Fan_Item, 16);
	}
	MeterValue = Cdoas_Get_Set_Value();
	MeterValue_L = MeterValue;
	return true;
}

bool CdaosOnLeave(ITUWidget* widget, char* param)
{
	return true;
}

bool CdaosOnTimer(ITUWidget* widget, char* param)
{
	static uint32_t SendEndTime = Rotate_SendCmd_Time;
	unsigned short Temp = 0;
	//用户手势操作
	if (Action_Cmd.User_Action == Left_Slide || Action_Cmd.User_Action == Right_Slide)
	{
		GotoMainMenu();//返回主菜单
		Clear_User_Action();
	}

	//设备操作
	MeterValue = Cdoas_Get_Set_Value();
	if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Cdaos_Status.status == 1)//设备开
	{
		if (Action_Cmd.User_Action == Clockwise_Rotation)//有用户操作
		{
			MeterValue += Action_Cmd.Action_Times;
			Cdoas_Set_Value(MeterValue);
			MessageFlag[MSG_GET_DEVICE_STATE_EN] = OFF;//关闭10s自动获取状态
			Clear_User_Action();
		}
		else if (Action_Cmd.User_Action == Anticlockwise_Rotation)
		{
			MeterValue -= Action_Cmd.Action_Times;
			if (MeterValue < 0)MeterValue = 0;
			Cdoas_Set_Value(MeterValue);
			MessageFlag[MSG_GET_DEVICE_STATE_EN] = OFF;//关闭10s自动获取状态
			Clear_User_Action();
		}
	}
	//设备状态执行
	if (MeterValue == MeterValue_L)
	{
		if (SendEndTime < Rotate_SendCmd_Time)
		{
			SendEndTime++;
			//停止操作0.6s后发送执行报文
			if (SendEndTime == Rotate_SendCmd_Time)
			{
				if (First_power_on == 0)
					RS485_Set_TFTDeviceState(DisplayValue.TFT_Display_Device);
				else
				{
					if (cdos_dev_value != MeterValue)
					{
						printf("Moorgen INFO : cdos_dev_value Data %d ,MeterValue %d\n", cdos_dev_value, MeterValue);
						First_power_on = 0;
					}
				}
				MessageFlag[MSG_GET_DEVICE_STATE_EN] = ON;//允许10s自动获取状态
			}
		}
	}
	else
	{
		SendEndTime = 0;
		MessageFlag[MSG_GET_DEVICE_STATE_EN] = OFF;//关闭10s自动获取状态
		if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.data[1] == CDOAS_SUPPOT_NULL)
		{
			if (MeterValue > 3)
				MeterValue = 3;
			TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Cdaos_Status.Cdaos_Status_Value.Byte.FanSpeed = MeterValue;
			TFT_Device_Cmd[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Heat_Status.status = CMD_CDOAS_SETFAN;//设置风速
			TFT_Device_Cmd[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Cdaos_Status.Cdaos_Status_Value.Byte.FanSpeed = MeterValue;
		}
		else if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.data[1] == CDOAS_SUPPOT_CO2)
		{
			TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Cdaos_Status.Set_Value = MeterValue * 35;
			TFT_Device_Cmd[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Heat_Status.status = CMD_CDOAS_SETCO2;//CO2
			TFT_Device_Cmd[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Cdaos_Status.Set_Value = MeterValue * 35;
		}
		else if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.data[1] == CDOAS_SUPPOT_PM25)
		{
			TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Cdaos_Status.Set_Value = MeterValue;
			TFT_Device_Cmd[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Heat_Status.status = CMD_CDOAS_SETCO2;//PM25
			TFT_Device_Cmd[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Cdaos_Status.Set_Value = MeterValue;
		}
		else if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.data[1] == CDOAS_SUPPOT_HUM)
		{
			TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Cdaos_Status.Set_Value = MeterValue + 30;
			TFT_Device_Cmd[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Heat_Status.status = CMD_CDOAS_SETCO2;//湿度
			TFT_Device_Cmd[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Cdaos_Status.Set_Value = MeterValue + 30;
		}
		//设置值状态显示更新
		Cdoas_Set_Value_Update(TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Cdaos_Status.Set_Value);
	}
	//设备状态更新
	if (MessageFlag[MSG_GUI_STATE_UPDATE] == ON)
	{
		//开关状态显示更新 
		Cdoas_Switch_State_Update(TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Cdaos_Status.status);
		//模式状态显示更新
		Cdoas_Mode_State_Update(TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Cdaos_Status.Mode);
		//设置值状态显示更新
		Cdoas_Set_Value_Update(TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Cdaos_Status.Set_Value);
		//设置值进度条显示更新
		if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.IT_Cdaos_Config.Suppot == CDOAS_SUPPOT_NULL)
		{
			Temp = TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Cdaos_Status.Cdaos_Status_Value.Byte.FanSpeed;
			printf("zdd-layercdaos.c:TFT_Device_State%s,Set_Value%d\n", "CDOAS_SUPPOT_NULL", Temp);
			Cdoas_Fan_State_Update(Temp);
		}
		else if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.IT_Cdaos_Config.Suppot == CDOAS_SUPPOT_HUM)
		{
			Temp = TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Cdaos_Status.Set_Value;
			printf("zdd-layercdaos.c:TFT_Device_State%s,Set_Value%d\n", "CDOAS_SUPPOT_HUM", Temp);
			Cdoas_Set_Value(Temp - 30);
		}
		else if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.IT_Cdaos_Config.Suppot == CDOAS_SUPPOT_CO2)
		{
			Temp = TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Cdaos_Status.Set_Value;
			printf("zdd-layercdaos.c:TFT_Device_State is %s,Set_Value = %d\n", "CDOAS_SUPPOT_CO2", Temp);
			Cdoas_Set_Value(Temp / 35);
		}
		else if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.IT_Cdaos_Config.Suppot == CDOAS_SUPPOT_PM25)
		{
			Temp = TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Cdaos_Status.Set_Value;
			printf("zdd-layercdaos.c:TFT_Device_State%s,Set_Value%d\n", "CDOAS_SUPPOT_PM25", Temp);
			Cdoas_Set_Value(Temp);
		}
		MeterValue = Cdoas_Get_Set_Value();
		MessageFlag[MSG_GUI_STATE_UPDATE] = OFF;
		Cdoas_SetType_Update();
	}
	if (MessageFlag[MSG_GUI_CONFIG_UPDATE] == ON)
	{
		//设置类型显示更新
		Cdoas_SetType_Update();
		MessageFlag[MSG_GUI_CONFIG_UPDATE] = OFF;
	}
	MeterValue_L = MeterValue;

	return true;
}

bool PopupButton_Cdaos_OFF_Press(ITUWidget* widget, char* param)
{
	TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Cdaos_Status.status = 0;//状态关
	TFT_Device_Cmd[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Cdaos_Status.status = 0x22;//命令关
	printf("Moorgen INFO : Touch to turn off the Cdaos\n");
	RS485_Set_TFTDeviceState(DisplayValue.TFT_Display_Device);
	return true;
}

bool Meter_Cdaos_Hum_Xuanzhuan_Changed(ITUWidget* widget, char* param)
{
	ituCircleProgressBarSetValue(CircleProgressBar_Cdaos_Hum, Meter_Cdaos_Hum_Xuanzhuan->value * 2);
	if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.IT_Cdaos_Config.Suppot == CDOAS_SUPPOT_HUM)
		Cdoas_Set_Value_Update(Meter_Cdaos_Hum_Xuanzhuan->value + 30);
	return true;
}

bool Meter_Cdaos_CO2_Xuanzhuan_Changed(ITUWidget* widget, char* param)
{
	ituCircleProgressBarSetValue(CircleProgressBar_Cdaos_CO2, Meter_Cdaos_CO2_Xuanzhuan->value);
	if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.IT_Cdaos_Config.Suppot == CDOAS_SUPPOT_CO2)
	if (abs(Meter_Cdaos_CO2_Xuanzhuan->value * 35 - TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Cdaos_Status.Set_Value) >= 35)
		Cdoas_Set_Value_Update(Meter_Cdaos_CO2_Xuanzhuan->value * 35);
	return true;
}

bool Meter_Cdaos_PM25_Xuanzhuan_Changed(ITUWidget* widget, char* param)
{
	ituCircleProgressBarSetValue(CircleProgressBar_Cdaos_PM25, Meter_Cdaos_PM25_Xuanzhuan->value);
	if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.IT_Cdaos_Config.Suppot == CDOAS_SUPPOT_PM25)
		Cdoas_Set_Value_Update(Meter_Cdaos_PM25_Xuanzhuan->value);
	return true;
}

bool Meter_Cdaos_Fan_Xuanzhuan_Changed(ITUWidget* widget, char* param)
{
	ituCircleProgressBarSetValue(CircleProgressBar_Cdaos_Fan, (Meter_Cdaos_Fan_Xuanzhuan->value + 1) * 25);
	if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.IT_Cdaos_Config.Suppot == CDOAS_SUPPOT_NULL)
		Cdoas_Set_Value_Update(Meter_Cdaos_Fan_Xuanzhuan->value);
	return true;
}
bool PopupButton_Cdaos_ON_Press(ITUWidget* widget, char* param)
{
	TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Cdaos_Status.status = 1;//状态开
	TFT_Device_Cmd[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Cdaos_Status.status = 0x21;//命令开
	printf("Moorgen INFO : Touch to turn on the Cdaos\n");
	RS485_Set_TFTDeviceState(DisplayValue.TFT_Display_Device);
	return true;
}


//开关状态显示更新
void Cdoas_Switch_State_Update(uint8_t Switch_State)
{
	//更具参数初始化界面
	if (Switch_State == 1)//打开
	{
		ituWidgetSetVisible(Container_Cdaos_Off, false);
		ituWidgetSetVisible(Container_Cdaos_On, true);
	}
	else//关闭
	{
		ituWidgetSetVisible(Container_Cdaos_On, false);
		ituWidgetSetVisible(Container_Cdaos_Off, true);
	}
}
//设置类型显示更新
void Cdoas_SetType_Update()
{
	ituWidgetSetVisible(Icon_Cdaos_Fan_Off, false);
	ituWidgetSetVisible(Icon_Cdaos_PM25_Off, false);
	ituWidgetSetVisible(Icon_Cdaos_CO2_Off, false);
	ituWidgetSetVisible(Icon_Cdaos_Hum_Off, false);
	ituWidgetSetVisible(Container_Cdaos_Fan_On, false);
	ituWidgetSetVisible(Container_Cdaos_PM25_On, false);
	ituWidgetSetVisible(Container_Cdaos_CO2_On, false);
	ituWidgetSetVisible(Container_Cdaos_Hum_On, false);
	if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.data[1] == CDOAS_SUPPOT_NULL)//不支持
	{
		ituWidgetSetVisible(Icon_Cdaos_Fan_Off, true);
		ituWidgetSetVisible(Container_Cdaos_Fan_On, true);
		Set_Rotate_Block(120);//旋转步进
	}
	else if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.data[1] == CDOAS_SUPPOT_CO2)//支持CO2
	{
		ituWidgetSetVisible(Icon_Cdaos_CO2_Off, true);
		ituWidgetSetVisible(Container_Cdaos_CO2_On, true);
		Set_Rotate_Block(30);//旋转步进
	}
	else if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.data[1] == CDOAS_SUPPOT_PM25)//支持PM2.5
	{
		ituWidgetSetVisible(Icon_Cdaos_PM25_Off, true);
		ituWidgetSetVisible(Container_Cdaos_PM25_On, true);
		Set_Rotate_Block(30);//旋转步进
	}
	else if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.data[1] == CDOAS_SUPPOT_HUM)//支持湿度
	{
		ituWidgetSetVisible(Icon_Cdaos_Fan_Off, true);
		ituWidgetSetVisible(Container_Cdaos_Hum_On, true);
		Set_Rotate_Block(30);//旋转步进
	}
	if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.data[1] == CDOAS_SUPPOT_NULL)//不支持
	{
		ituWidgetSetVisible(Container_Cdaos_Mode_Fan, false);
		ituWidgetSetVisible(Container_Cdaos_Only_Fan, false);
	}
	else if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.data[4] != 0)//支持模式
	{
		ituWidgetSetVisible(Container_Cdaos_Mode_Fan, true);
		ituWidgetSetVisible(Container_Cdaos_Only_Fan, false);
	}
	else
	{
		ituWidgetSetVisible(Container_Cdaos_Mode_Fan, false);
		ituWidgetSetVisible(Container_Cdaos_Only_Fan, true);
	}
}

//风速状态显示更新
void Cdoas_Fan_State_Update(uint8_t State)
{
	//设置温度值
	ituMeterSetValue(Meter_Cdaos_Fan_Xuanzhuan, State);
}
//模式状态显示更新
void Cdoas_Mode_State_Update(uint8_t State)
{
	uint8_t i;
	for (i = 0; i < 7; i++)
	{
		ituWidgetSetVisible(PopupButton_Cdaos_Mode[i], false);
	}
	if (State != 0)//存在模式状态
	{
		if (State <= 6)
		{
			ituWidgetSetVisible(PopupButton_Cdaos_Mode[State - 1], true);
		}
		else
		{
			ituWidgetSetVisible(PopupButton_Cdaos_Mode[6], true);//其他模式
		}
	}
}
//设置值更新
void Cdoas_Set_Value_Update(uint16_t Set_Value)
{
	char TextString[20];
	if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.data[1] == CDOAS_SUPPOT_NULL)//不支持
	{
		if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Cdaos_Status.Cdaos_Status_Value.Byte.FanSpeed == 0)//自动
		{
			ituTextSetString(Text_Cdaos_Fan_Value, "AUTO");//显示字符
			ituTextSetFontSize(Text_Cdaos_Fan_Value, 40);
		}
		else
		{
			itoa(TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Cdaos_Status.Cdaos_Status_Value.Byte.FanSpeed, TextString, 10);//转换成字符串
			ituTextSetString(Text_Cdaos_Fan_Value, TextString);//显示字符
			ituTextSetFontSize(Text_Cdaos_Fan_Value, 56);
		}
	}
	else if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.data[1] == CDOAS_SUPPOT_CO2)
	{
		itoa(Set_Value, TextString, 10);//转换成字符串
		ituTextSetString(Text_Cdaos_CO2_Value, TextString);//显示字符
		ituTextSetFontSize(Text_Cdaos_CO2_Value, 56);
	}
	else if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.data[1] == CDOAS_SUPPOT_PM25)
	{
		itoa(Set_Value, TextString, 10);//转换成字符串
		ituTextSetString(Text_Cdaos_PM25_Value, TextString);//显示字符
		ituTextSetFontSize(Text_Cdaos_PM25_Value, 56);
	}
	else if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.data[1] == CDOAS_SUPPOT_HUM)
	{
		itoa(Set_Value, TextString, 10);//转换成字符串
		ituTextSetString(Text_Cdaos_Hum_Value, TextString);//显示字符
		ituTextSetFontSize(Text_Cdaos_Hum_Value, 56);
	}
}
void Cdoas_Set_Value(uint16_t Set_Value)
{
	if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.data[1] == CDOAS_SUPPOT_NULL)
	{
		if (Set_Value > 3)Set_Value = 3;
		//设置风速值
		ituMeterSetValue(Meter_Cdaos_Fan_Xuanzhuan, Set_Value);
	}
	else if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.data[1] == CDOAS_SUPPOT_CO2)
	{
		if (Set_Value > 100)Set_Value = 100;
		//设置风速值
		ituMeterSetValue(Meter_Cdaos_CO2_Xuanzhuan, Set_Value);
	}
	else if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.data[1] == CDOAS_SUPPOT_PM25)
	{
		if (Set_Value > 100)Set_Value = 100;
		//设置风速值
		ituMeterSetValue(Meter_Cdaos_PM25_Xuanzhuan, Set_Value);
	}
	else if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.data[1] == CDOAS_SUPPOT_HUM)
	{
		if (Set_Value > 50)Set_Value = 50;
		//设置风速值
		ituMeterSetValue(Meter_Cdaos_Hum_Xuanzhuan, Set_Value);
	}
}
uint16_t Cdoas_Get_Set_Value(void)
{
	if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.data[1] == CDOAS_SUPPOT_NULL)
	{
		return Meter_Cdaos_Fan_Xuanzhuan->value;
	}
	else if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.data[1] == CDOAS_SUPPOT_CO2)
	{
		return Meter_Cdaos_CO2_Xuanzhuan->value;
	}
	else if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.data[1] == CDOAS_SUPPOT_PM25)
	{
		return Meter_Cdaos_PM25_Xuanzhuan->value;
	}
	else if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_Config_Value.data[1] == CDOAS_SUPPOT_HUM)
	{
		return Meter_Cdaos_Hum_Xuanzhuan->value;
	}
}